package com.smz.service.impl;


import com.smz.dao.TProductionLineDAO;
import com.smz.entity.TProductionLine;
import com.smz.service.TProductionLineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Kan
 * @Time 2021-11-16-20:49
 */
@Service
public class TProductionLineServiceImpl implements TProductionLineService {
    @Autowired
    TProductionLineDAO tProductionLineDAO;


    /**
     * 查询所有产线
     * @return
     */
    @Override
    public List<TProductionLine> findAllProductionLine() {
        return tProductionLineDAO.selectAllLine();
    }

    /**
     * 添加生产线
     * @param pro
     * @return
     */
    @Override
    public String addProduction(TProductionLine pro) {
        tProductionLineDAO.insert(pro);
        return "ok";
    }

    /**
     * 修改生产线
     * @param pro
     * @return
     */
    @Override
    @Transactional
    public String modifyProduction(TProductionLine pro) {
        tProductionLineDAO.updateById(pro);
        if (pro.getOperator()!=null){
            Integer count = tProductionLineDAO.updateOperator(pro.getOperator(), pro.getId());
            if (count!=0){
                return "ok";
            }else {
                return "no";
            }
        }
        return "ok";
    }

    /**
     * 删除生产线
     * @param id
     * @return
     */
    @Override
    @Transactional
    public String removeLine(Integer id) {
            tProductionLineDAO.updateLineInOrder(id);
            tProductionLineDAO.deleteById(id);
            return "ok";
        }

    @Override
    public List<String> selectAllOperators() {
        return tProductionLineDAO.selectAllOperator();
    }
}

